/*
 * Created by 2006-1-29 23:20:55
 * $Id: Config.java 36 2006-06-22 15:00:10Z wjx $
 */
package com.someok.base;

import org.apache.log4j.Logger;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.ConfigurationFactory;


/**
 * <code>Config</code> is <code>Configuration</code> class's adapter.
 *
 * <p>
 * <a href="Config.java.html"><i>View Source</i></a>
 * </p>
 *
 * @author wjx
 * @version $Revision: 36 $ $Date: 2006-06-22 23:00:10 +0800 (星期四, 22 六月 2006) $
 */
public class Config {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(Config.class);

	private static final String SOMEOK_CONFIG_XML = "/someok-config.xml";


	private static Configuration conf = null;

	static {
		ConfigurationFactory factory = new ConfigurationFactory();
		URL configURL = Config.class.getResource(SOMEOK_CONFIG_XML);
		factory.setConfigurationURL(configURL);
		try {
			conf = factory.getConfiguration();
			logger.info("系统配置文件初始化成功，配置文件为：" + SOMEOK_CONFIG_XML);
		} catch (ConfigurationException e) {
			logger.error("系统配置文件初始化过程中出现错误 ： ", e);
		}

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		logger.debug("begin.......");
		Config config = Config.getInstance();
		System.out.println(config.getString("service.comments.form"));
		config.setProperty("aaa", "aaaaaaa");
		System.out.println(config.getString("aaa"));
		System.out.println(config.getString("file.encoding")); // system
	}

	private Config() {
	}

	/**
	 * @return
	 */
	public static Config getInstance() {
		return new Config();
	}

	public static Configuration getConfiguration() {
		return conf;
	}

	public Configuration subset(String arg0) {
		return conf.subset(arg0);
	}

	public boolean isEmpty() {
		return conf.isEmpty();
	}

	public boolean containsKey(String arg0) {
		return conf.containsKey(arg0);
	}

	public void addProperty(String arg0, Object arg1) {
		conf.addProperty(arg0, arg1);
	}

	public void setProperty(String arg0, Object arg1) {
		conf.setProperty(arg0, arg1);
	}

	public void clearProperty(String arg0) {
		conf.clearProperty(arg0);
	}

	public void clear() {
		conf.clear();
	}

	public Object getProperty(String arg0) {
		return conf.getProperty(arg0);
	}

	public Iterator getKeys(String arg0) {
		return conf.getKeys(arg0);
	}

	public Iterator getKeys() {
		return conf.getKeys();
	}

	public Properties getProperties(String arg0) {
		return conf.getProperties(arg0);
	}

	public boolean getBoolean(String arg0) {
		return conf.getBoolean(arg0);
	}

	public boolean getBoolean(String arg0, boolean arg1) {
		return conf.getBoolean(arg0, arg1);
	}

	public Boolean getBoolean(String arg0, Boolean arg1)
			throws NoClassDefFoundError {
		return conf.getBoolean(arg0, arg1);
	}

	public byte getByte(String arg0) {
		return conf.getByte(arg0);
	}

	public byte getByte(String arg0, byte arg1) {
		return conf.getByte(arg0, arg1);
	}

	public Byte getByte(String arg0, Byte arg1) {
		return conf.getByte(arg0, arg1);
	}

	public double getDouble(String arg0) {
		return conf.getDouble(arg0);
	}

	public double getDouble(String arg0, double arg1) {
		return conf.getDouble(arg0, arg1);
	}

	public Double getDouble(String arg0, Double arg1) {
		return conf.getDouble(arg0, arg1);
	}

	public float getFloat(String arg0) {
		return conf.getFloat(arg0);
	}

	public float getFloat(String arg0, float arg1) {
		return conf.getFloat(arg0, arg1);
	}

	public Float getFloat(String arg0, Float arg1) {
		return conf.getFloat(arg0, arg1);
	}

	public int getInt(String arg0) {
		return conf.getInt(arg0);
	}

	public int getInt(String arg0, int arg1) {
		return conf.getInt(arg0, arg1);
	}

	public Integer getInteger(String arg0, Integer arg1) {
		return conf.getInteger(arg0, arg1);
	}

	public long getLong(String arg0) {
		return conf.getLong(arg0);
	}

	public long getLong(String arg0, long arg1) {
		return conf.getLong(arg0, arg1);
	}

	public Long getLong(String arg0, Long arg1) {
		return conf.getLong(arg0, arg1);
	}

	public short getShort(String arg0) {
		return conf.getShort(arg0);
	}

	public short getShort(String arg0, short arg1) {
		return conf.getShort(arg0, arg1);
	}

	public Short getShort(String arg0, Short arg1) {
		return conf.getShort(arg0, arg1);
	}

	public BigDecimal getBigDecimal(String arg0) {
		return conf.getBigDecimal(arg0);
	}

	public BigDecimal getBigDecimal(String arg0, BigDecimal arg1) {
		return conf.getBigDecimal(arg0, arg1);
	}

	public BigInteger getBigInteger(String arg0) {
		return conf.getBigInteger(arg0);
	}

	public BigInteger getBigInteger(String arg0, BigInteger arg1) {
		return conf.getBigInteger(arg0, arg1);
	}

	public String getString(String arg0) {
		return conf.getString(arg0);
	}

	public String getString(String arg0, String arg1) {
		return conf.getString(arg0, arg1);
	}

	public String[] getStringArray(String arg0) {
		return conf.getStringArray(arg0);
	}

	public List getList(String arg0) {
		return conf.getList(arg0);
	}

	public List getList(String arg0, List arg1) {
		return conf.getList(arg0, arg1);
	}

}
